package com.aigou.admin.controller;


import com.aigou.admin.entity.User;
import com.aigou.admin.service.UserService;
import com.aigou.admin.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 添加用户信息的Servlet
 */
@WebServlet("/saveUser")
public class SaveUserController extends HttpServlet {
    //调用service
    private UserService userService = new UserServiceImpl();

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得用户id
        String userId = req.getParameter("userId");
        String userName = req.getParameter("userName");
        String userPwd = req.getParameter("userPwd");
        String userType = req.getParameter("userType");
        User user = new User(userId,userName,userPwd,Integer.valueOf(userType));
        //查询用户
        boolean rs = userService.save(user);
        //转换为JSON,通过流发送给客户端
        resp.getWriter().write(String.valueOf(rs));
    }
}
